<template>
  <!-- 公共驳回 -->
  <el-dialog
    title="驳回"
    v-model="dialogVisible"
    width="30%"
    :before-close="handleClose"
  >
    <el-form :model="ruleForm" :rules="rules" ref="ruleFormRef">
      <el-row>
        <el-col :span="24">
          <el-form-item label="驳回原因" :prop="field">
            <el-input
              type="textarea"
              class="wh"
              maxlength="100"
              show-word-limit
              v-model="ruleForm[field]"
              placeholder="请输入驳回原因"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <template #footer>
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="handleSubmit">确 定</el-button>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, onMounted } from "vue";
import { deepClone } from "@/utils/index.js";
import {ElMessageBox} from 'element-plus'
const emits = defineEmits(["change"]);
const dialogVisible = ref(false);
const ruleFormRef = ref();
const ruleForm = ref({});
const rules = ref({});

const props = defineProps({
  field: {
    type: String,
    default: "rejection",
  },
});
onMounted(() => {
  rules.value[props.field || "rejection"] = [
    { required: true, message: "请输入驳回原因", trigger: "blur" },
  ];
});
const handleOpen = (item) => {
  dialogVisible.value = true;
  ruleForm.value = deepClone(item);
};
const handleSubmit = () => {
  ruleFormRef.value.validate((valid) => {
    if (valid) {
      ElMessageBox.confirm("确认执行此操作吗？", "系统提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        const data = deepClone(ruleForm.value);
        emits("change", data);
        handleClose();
      });
    }
  });
};
const handleClose = () => {
  ruleFormRef.value.resetFields();
  dialogVisible.value = false;
};
defineExpose({
  handleOpen,
});
</script>